package com.hkts.beltweigher.master.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hkts.beltweigher.master.entity.RandomNumberSettings;
import com.hkts.beltweigher.master.mapper.RandomNumberSettingsMapper;
import com.hkts.beltweigher.master.service.IRandomNumberSettingsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hkts.beltweigher.utils.ResultUtil;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hml
 * @since 2024-04-18
 */
@Service
@Transactional
public class RandomNumberSettingsServiceImpl extends ServiceImpl<RandomNumberSettingsMapper, RandomNumberSettings> implements IRandomNumberSettingsService {


    @Autowired
    private RandomNumberSettingsMapper randomNumberSettingsMapper;

    @Override
    public IPage<RandomNumberSettings> selectPage(Page<RandomNumberSettings> page, RandomNumberSettings randomNumberSettings) {
        QueryWrapper<RandomNumberSettings> query = Wrappers.query();
        return randomNumberSettingsMapper.selectPage(page, query);
    }


    @Override
    public List<RandomNumberSettings> selectList(RandomNumberSettings randomNumberSettings) {
        QueryWrapper<RandomNumberSettings> query = Wrappers.query();
        return randomNumberSettingsMapper.selectList(query);
    }


    @Override
    public Boolean randomNumberSettingsUpdate(Float coefficient){
        RandomNumberSettings randomNumberSettings = new RandomNumberSettings();
        List<RandomNumberSettings> randomNumberSettingsList = selectList(randomNumberSettings);
        List<RandomNumberSettings> numberSettingsList = new ArrayList<>();
        for (int i = 0; i < randomNumberSettingsList.size(); i++) {
            randomNumberSettingsList.get(i).setCoefficient(coefficient);
            numberSettingsList.add(randomNumberSettingsList.get(i));
        }
        boolean b = saveOrUpdateBatch(numberSettingsList);
        if (b){
            return true;
        }else {
            return false;
        }
    }


}
